using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Portal.Core.DAL;

namespace Portal.BO.Editoral.BanDocViet
{
    public class FeedBackNewsHelper
    {
        public FeedBackNewsHelper() { }


        public static DataTable GetList(int PageSize, int StartRow, string title, string cat_id)
        {
            int startIndex = StartRow;
            int endIndex = startIndex + PageSize;
            if (title == null)
                title = "";

            using (MainDB objMain = new MainDB())
            {
                return objMain.StoredProcedures.FeedBack_GetList(title, cat_id, startIndex.ToString(), endIndex.ToString());
            }
        }

        public static int CountList(string title, string cat_id)
        {
            if (title == null)
                title = "";

            using (MainDB objMain = new MainDB())
            {
                return Convert.ToInt32(objMain.StoredProcedures.FeedBack_CountList(title, cat_id).Rows[0][0]);
            }
        }


        public static DataTable FeedBack_GetListByNewsId(string strNewsId)
        {
            DataTable dt = new DataTable();
            if (strNewsId.Trim() != "")
            { 
                using (MainDB objMain = new MainDB())
                {
                    dt = (DataTable)objMain.CallStoredProcedure("GetListFeedBackNewsByNewsID", new object[] { strNewsId }, new string[] { "@news_id" }, true); 
                    //.SelectQuery("Select * From FeedBackNews Where News_ID = " + strNewsId);
                }

                //using (MainDB objdb = new MainDB())
                //{
                //    object o = objdb.CallStoredProcedure("s_CountCommentIn", new object[] { comment, type, catIDs, newsTitle }, new string[] { "@comment", "@type", "@catIDs", "@newsTitle" }, false);
                //    return o == null ? 0 : (int)o;
                //}
                
            }
            return dt;
        }

        public static DataTable FeedBack_GetFeedbackNewsInfo(string strFeedBack_ID)
        {
            DataTable dt = new DataTable();
            if (strFeedBack_ID.Trim() != "")
            {
                using (MainDB objMain = new MainDB())
                {
                    dt = objMain.SelectQuery("Select * From FeedBackNews Where FeedBack_ID = " + strFeedBack_ID);
                }

            }
            return dt;
        }

        public static FeedBackNewsRow FeedBack_GetByPramiryKey(string strId)
        {
            FeedBackNewsRow objFeedBack = new FeedBackNewsRow();
            if (strId.Trim() != "")
            {
                using (MainDB objMain = new MainDB())
                {
                    objFeedBack = objMain.FeedBackNewsCollection.GetByPrimaryKey(Convert.ToInt64(strId));
                }

            }

            return objFeedBack;
        }

        public static void FeedBack_Update(FeedBackNewsRow objFeedBack)
        {
            using (MainDB objMain = new MainDB())
            {
                objMain.FeedBackNewsCollection.Update(objFeedBack);
            }
        }

        public static void DeleteFeedBackById(string strFeedBackId)
        {
            if (strFeedBackId.Trim() != "")
            {
                using (MainDB objMain = new MainDB())
                {
                    objMain.SelectQuery("Delete FeedBackNews Where FeedBack_ID = " + strFeedBackId);
                }

            }
        }

        public static string CountFeedBackNews()
        {
            using (MainDB objMain = new MainDB())
            {
                return objMain.StoredProcedures.CountFeedBackNews().Rows[0][0].ToString();
            }
        }

        public static void UpdateNewsMode(string FeedBack_ID, string strNewsMode)
        {
            using (MainDB objMain = new MainDB())
            {
                objMain.SelectQuery(" Update FeedBackNews Set News_Mode = " + strNewsMode + " Where FeedBack_ID = " + FeedBack_ID);
            }
        }
    }
}
